import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5 import uic

class ShowFullWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.ui = uic.loadUi(r'D:\TimeCount\venv\ui\ShowFullWindow.ui')

        LcdShow=self.ui.findChild(QLCDNumber,'lcdNumber')
        # LcdShow.raise_()
        LcdShow.resize(50,50)
        LcdShow.display('00:00')
        print(LcdShow.size())

        # 设置初始背景图片
        self.set_background_image(r"D:\TimeCount\venv\ui\image.png")

        # 创建垂直布局
        layout = QGridLayout()

        # 找到QLCDNumber控件
        LcdShow = self.ui.findChild(QLCDNumber, 'lcdNumber')
        LcdShow.setMinimumSize(200,200)
        LcdShow.setMaximumSize(200,200)

        # 添加伸缩项将QLCDNumber显示在窗体中央
        # layout.addStretch(1)
        layout.addWidget(LcdShow)
        # layout.addStretch(1)
        # 设置布局为窗口的主布局
        self.ui.setLayout(layout)
        # 连接窗口的resizeEvent事件到自定义方法
        self.ui.resizeEvent = self.custom_resize_event
        # print(self.resizeEvent)
        self.ui.show()

        # # 为LcdShow添加鼠标事件处理程序
        # LcdShow.mousePressEvent = self.ui.mousePress
        # LcdShow.mouseMoveEvent = self.ui.mouseMove
        #
        # self.ui.dragging = False
        # self.ui.drag_start_position = None

    # def mousePress(self, event):
    #     if event.button() == Qt.LeftButton:
    #         self.ui.dragging = True
    #         self.ui.drag_start_position = event.globalPos()
    #         self.ui.drag_start_size = LcdShow.size()
    #
    # def mouseMove(self, event):
    #     if self.ui.dragging:
    #         globalPos = event.globalPos()
    #         delta = globalPos - self.ui.drag_start_position
    #         new_size = self.ui.drag_start_size + delta
    #         LcdShow.resize(new_size)
    #         LcdShow.setFixedSize(new_size)
    #
    # def mouseRelease(self, event):
    #     if event.button() == Qt.LeftButton:
    #         self.ui.dragging = False
    #

    def set_background_image(self, image_path):
        pixmap = QPixmap(image_path)
        size = self.ui.size()

        # 缩放背景图片以适应窗体大小
        background = pixmap.scaled(size)

        palette = QPalette()
        palette.setBrush(QPalette.Window, QBrush(background))

        # 设置窗体的背景
        self.ui.setPalette(palette)

    def custom_resize_event(self, event):
        # 当窗口大小发生变化时，重新设置背景图片
        self.set_background_image(r"D:\TimeCount\venv\ui\image.png")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = ShowFullWindow()
    sys.exit(app.exec_())
